/**
 * Point.java
 * colourmap
 * Copyright (C) 2010 Alan W.F. Boyd
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * You can contact the author via the google code web page for the project
 * <http://colourmap.googlecode.com>
 */
package com.googlecode.colourmap;

/**
 * A point object represents a pairing of x and y values to represent a point in space
 *
 * @author Alan W.F. Boyd
 */
public class Point
{
	/** The x coordinate */
	public float x;
	
	/** The y coordinate */
	public float y;
	
	/**
	 * Constructor for a Point object
	 * @param x the x coordinate
	 * @param y the y coordinate
	 */
	public Point(float x, float y)
	{
		this.x = x;
		this.y = y;
	}
	
	/**
	 * Converts the point into a string, showing the x and y coordinates
	 */
	public String toString()
	{
		return this.x + "," + this.y;
	}
	
	/**
	 * Calculating the cartesian distance between two Point objects
	 * @param c the second point
	 * @return the cartesian distance between this Point and the provided Point
	 */
	public double distance(Point c)
	{
		return Math.sqrt(Math.pow(c.x - this.x, 2) + Math.pow(c.y - this.y, 2));
	}
	
	/**
	 * Two points are equal if and only if their coordinates are the same
	 * @param o the object to compare
	 * @return a boolean indicating whether the two objects are the same are not
	 */
	public boolean equals(Object o)
	{
		if (!(o instanceof Point))
			return false;
		
		Point p = (Point) o;
		return (x == p.x && y == p.y);
	}
	
	/**
	 * Overrides the hashcode method (necessary due to overriding the equals method)
	 * @return the hashcode of this object
	 */
	public int hashCode()
	{
		return (int)(x*y);
	}
	
	
}
